
#ifndef _MPEG_H
#define _MPEG_H


typedef enum
{
	DSP_INITIALIZE,
	DSP_WAIT,
	DSP_IDLE,
	DSP_WAITTask,
	DSP_POWERON,
	DSP_LOADING,
	DSP_UPGRADE,
	DSP_PLAY,
	DSP_GUI
}DSP_STATE;
///#define DISC_READ_ERROR	1

/*--------------------------copy from mpeg----------------------------*/
typedef struct{/*2Bytes*/
	uchar cmdId;
	uchar param;
}MCU_COMMAND;

typedef struct{
	///unsigned DownmixEn	:1;
	unsigned MuteOn			:1;
	unsigned iPodConnected	:1;
	unsigned F_SD_EXIT      :1;
	unsigned F_USB_EXIT    	:1;
	unsigned F_DISC_EXIT   	:1;
	unsigned NaviConnected	:1;
	unsigned MPEG_PVIDEO	:1;
}DEVICE_SETTING;
#if	0//ndef D_USENAVI_DSPSETUPMENU	
typedef struct {//5Bytes
	 uchar BassCntFreq;
	 uchar TrebleCntFreq;
	 uchar SWFilter;
	 uchar SWPhase;
	 uchar BassQFactor;
///	 uchar FMAMGain;
///	 uchar DVDGain;
///	 uchar AUXGain;
///	 uchar iPodGain;
	
}ASP_SETTING;
#endif
typedef struct {/*7Bytes*/
	uchar EQMode;
	uchar BassLevel;
	uchar TrebleLevel;
	uchar SWLevel;
	uchar LoudLevel;
	uchar FadeLevel;
	uchar BalanceLevel;
///	ASP_SETTING ASPSetting;
}AUDIO_SETTING;

typedef struct{/*3///7Bytes*/
	uchar ClockSecond;
	uchar ClockMinute;
	uchar ClockHour;
	////uchar ClockDay;
	////uchar ClockDate;
	////uchar ClockMonth;
	////uchar ClockYear;
}CLOCK_TIME;

typedef struct {/*2Bytes*/
	uchar SysSettingFlag;
	uchar OsdLanguage;

}GENERAL_SETTING;

#if	0//ndef D_USENAVI_DSPSETUPMENU	
typedef struct {/*1Bytes*/
	uchar ScreenBrightness;

}SCREEN_SETTING;
#endif

typedef struct {/*15+1 bytes*/
	GENERAL_SETTING GenSetting;/*2Bytes*/
	///SCREEN_SETTING 	ScreenSetting;/*2Bytes*/
	CLOCK_TIME Clock;
	AUDIO_SETTING AudSetting;/*7Bytes*/
	//uchar RDSSetting;
}SYSTEM_SETTINGS;
#if	0///ndef D_USENAVI_DSPSETUPMENU	
typedef struct {/*3Bytes*/

	 uword CurFreq;
///	 uword TunerFlag;
#if 1
	 uchar CurPreset;
	 uchar Band;
	 uchar TunerStereo;
#endif
}RADIO_INFO;

#ifndef D_RADIO_PRESET_NUM12
#define MAX_PRESET_STATIONS	6
#else
#define MAX_PRESET_STATIONS	12
#endif
typedef struct {//24 bytes
	uword freq[MAX_PRESET_STATIONS];
}FREQ_LIST;

#endif
/*
typedef union {
	RADIO_INFO RadioInfo;
}MCU_INFO;
typedef struct{//66Bytes
	uword DataID;
	uchar Data[64];
}REFLASH_DATA;
*/


typedef struct
{
	uchar DeviceStatus;
	///uchar DiscType;
	///uchar AudioType;
	uchar MainState;
	///uchar PlayState;
	///uchar PlayMode;

} MPLAY_INFO;

/*---------------------------DVDP command list--------------------------------*/
typedef enum
{
	EVT_DVDP_NONE,
	EVT_DVDP_POWER_ON		,
	EVT_DVDP_POWER_OFF		,
	EVT_DVDP_EMERGENCY_OFF	,
	EVT_DVDP_RESET			,
	EVT_DVDP_EJECT			,
	EVT_DVDP_LAST_MEMORY	,	
	EVT_DVDP_FRONT_SRC     , 
	EVT_DVDP_REAR_SRC      , 
	EVT_DVDP_SET_VOLUME,
	EVT_DVDP_IPOD_ON,
	EVT_DVDP_IPOD_OFF,
	EVT_DVDP_SET_RDS,
	EVT_DVDP_SET_BAND
}CMD_MPEG;

/*--------------------------Main State----------------------------------------

typedef enum{
	MST_POWER_OFF			=0,
	MST_POWER_DOWN			=1,
	MST_NO_DISC				=2,
	MST_UNKNOWN_DISC		=3,
	MST_TRAY_OPENING		=4,
	MST_TRAY_CLOSING		=5,
	MST_TRAY_OPEN			=6,
	MST_LOADING				=7,
	MST_DISC_READY			=8,
	MST_MENU_STATE			=9,
	MST_DTA_MODE			= 10,
	MST_AUDIO_MENU_OPERATION	= 11,
	MST_TV_STATE				= 12
}MAIN_STATE;

*/
///spi use
ext    uchar Comd_Id_IN_Buffer;
ext    uchar Data_Length_IN_Buffer;


ext    uchar  MPEG_IAP_timer;
////ext    uchar MPEG_ResetDelay;
ext    DSP_STATE DSP_state;

ext    uchar MPEG_Timer;
///ext    uchar MPEG_TryTimes;
ext    uchar  MPEG_CommCnt;
////ext    uchar MPEG_ReplyAck_Times;
ext  uchar USB_reset_detect_Timer;

////ext    MPLAY_INFO MPlayInfo;
////#define MPEG_CUR_MAIN_STATE		MPlayInfo.MainState

typedef union
{
	uchar			byte;
	DEVICE_SETTING 	field;
}_DEVICE_SETTING;

ext  _DEVICE_SETTING				Device_Status;///get state from mpeg
///#define MPEG_DOWNMIX_SETTING		Device_Status.field.DownmixEn
#define SYS_MUTE					Device_Status.field.MuteOn
#define IPOD_CONNECTED			Device_Status.field.iPodConnected
#define IsExistIpod					IPOD_CONNECTED==1

#define F_Exist_SD					Device_Status.field.F_SD_EXIT
#define F_Exist_USB				Device_Status.field.F_USB_EXIT
#define F_Exist_DISC				Device_Status.field.F_DISC_EXIT
#define NAVI_CONNECTED			Device_Status.field.NaviConnected
#define MPEG_VIDEO_PLAY			Device_Status.field.MPEG_PVIDEO
#define IsExistSDCard				F_Exist_SD==1		
#define ResetRelease()				{RUNNING_MPEG;Mpeg_Rst_StartOk=1;}


ext     uchar Mpeg_Disc_Status;///get state from mpeg

#define F_MPEG_NO_DISC				Mpeg_Disc_Status==0
#define F_MPEG_DISC_READY			Mpeg_Disc_Status==1
#define F_MPEG_DISC_OPEN				Mpeg_Disc_Status==2
#define F_MPEG_DISC_OPENNING		Mpeg_Disc_Status==3	
#define F_MPEG_DISC_CLOING			Mpeg_Disc_Status==4	
#define F_MPEG_BAD_DISC				Mpeg_Disc_Status==5

///ext     uchar Rx_Mpeg_FSource;///get state from mpeg
///ext     uchar Rx_Mpeg_RSource;///get state from mpeg

///extern bool IS_MPEG_INMENU(void);
extern void Mpeg_MainPro(void);
extern void  Mpeg_Command(uchar CmdId,uchar Parameter);
extern void Mpeg_Reset(void);
///ern bool IS_MPEG_BUSY(void);
 
 #ifdef DEBUG_SPI_PROTOCOL
extern void Mpeg_SPI_Test(void);
 #endif

 #define MPEG_PowerUp()		Mpeg_Command(UICC_POWER,1)
#define MPEG_PowerDown()	Mpeg_Command(UICC_POWER,0)
#endif
